import { Module } from '@nestjs/common';
import { PrismaModule } from './module/prisma/prisma.module';
import { UserModule } from './module/user/user.module';
import configuration from './config/index';
import { ValidationPipe } from '@nestjs/common';
import { APP_GUARD, APP_PIPE } from '@nestjs/core';
import { RedisModule } from './module/redis/redis.module';
import { EmailModule } from './module/email/email.module';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { JwtModule } from '@nestjs/jwt';
import { AuthGuard } from './common/guard/auth.guard';
import { FriendshipModule } from './module/friendship/friendship.module';
import { ChatroomModule } from './module/chatroom/chatroom.module';
import { ChatModule } from './module/chat/chat.module';
import { ChatHistoryModule } from './module/chat-history/chat-history.module';

@Module({
    imports: [
        ConfigModule.forRoot({
            isGlobal: true,
            cache: true,
            load: [configuration]
        }),
        JwtModule.registerAsync({
            global: true,
            useFactory: (configService: ConfigService) => ({
                secret: configService.get("jwt.secretkey"),
            }),
            inject: [ConfigService],
        }),
        PrismaModule, UserModule, RedisModule, EmailModule, FriendshipModule, ChatroomModule, ChatModule, ChatHistoryModule],
    controllers: [],
    providers: [
        {
            provide: APP_GUARD,
            useClass: AuthGuard
        }
    ],
})
export class AppModule { }
